<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <link rel="stylesheet" href="../css/fx.css">
        <!-- 引入组件库 -->
        <script type="text/javascript" src="../js/jquery.min.js"></script>
        <script src="../js/vue.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script src="../js/axios-0.18.0.js"></script>
        <style>
            .avatar-uploader .el-upload {
                border: 1px dashed #d9d9d9;
                border-radius: 6px;
                cursor: pointer;
                position: relative;
                overflow: hidden;
            }
            .avatar-uploader .el-upload:hover {
                border-color: #409EFF;
            }
            .avatar-uploader-icon {
                font-size: 28px;
                color: #8c939d;
                width: 178px;
                height: 178px;
                line-height: 178px;
                text-align: center;
            }
            .avatar {
                width: 178px;
                height: 178px;
                display: block;
            }
            .datatable {
                position: relative;
                box-sizing: border-box;
                -webkit-box-flex: 1;
                width: 100%;
                max-width: 100%;
                font-size: 14px;
                color: rgb(96, 98, 102);
                overflow: hidden;
                flex: 1 1 0%;
            }
            .datatable td, .datatable th {
                padding: 12px 0;
                min-width: 0;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                text-overflow: ellipsis;
                vertical-align: middle;
                position: relative;
                text-align: left;
            }
        </style>
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>预约管理<small>预约列表</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>预约管理</el-breadcrumb-item>
                    <el-breadcrumb-item>预约列表</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <div class="">
                        <el-input placeholder="手机号"
                                  v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                            <el-date-picker
                                    v-model="dateRangeStr"
                                    type="daterange"
                                    align="right"
                                    unlink-panels
                                    range-separator="至"
                                    start-placeholder="开始日期"
                                    end-placeholder="结束日期"
                                    :picker-options="pickerOptions">
                            </el-date-picker>
                        <el-button @click="findPage()" class="butT dalfBut">查询
                        </el-button>
                        <el-button type="primary" class="butT btn-fx-bubble"
                                   @click="handleCreate()">新建</el-button>
                    </div>
                    <template v-if="dataList == null">
                        <div align="center">
                            <svg class="fx-wait-icon-red-circle-svg-dash-svg" viewBox="25 25 50 50">
                                <circle class="fx-wait-icon-red-circle-svg-dash-circle" cx="50" cy="50" r="20"></circle>
                            </svg>
                        </div>
                    </template>
                    <template v-else>
                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column type="index" align="center" label="序号"></el-table-column>
                        <el-table-column prop="orderDate" label="预约日期" align="center"></el-table-column>
                        <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                        <el-table-column prop="sex" label="性别" align="center">
                            <template slot-scope="scope">
                                <span>{{ scope.row.sex == '0' ? '不限' : scope.row.sex == '1' ? '男' : '女'}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="idCard" label="身份证号" align="center"></el-table-column>
                        <el-table-column prop="phoneNumber" label="电话号码" align="center"></el-table-column>
                        <el-table-column prop="orderType" label="预约方式" align="center"></el-table-column>
                        <el-table-column prop="orderStatus" label="订单状态" align="center"></el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除
                                </el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    </template>
                    <div class="pagination-container">
                        <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total">
                        </el-pagination>
                    </div>
                    <!-- 新增标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="新增套餐" :visible.sync="dialogFormVisible">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="基本信息" name="first">
                                        <el-form ref="dataAddForm" :rules="rules"
                                                 label-position="right"
                                                 label-width="100px"
                                                 :model="formData">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="编码"
                                                                  prop="code">
                                                        <el-input v-model="formData.code"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="名称"
                                                                  prop="name">
                                                        <el-input v-model="formData.name"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="适用性别">
                                                        <el-select v-model="formData.sex">
                                                            <el-option label="不限" value="0"></el-option>
                                                            <el-option label="男" value="1"></el-option>
                                                            <el-option label="女" value="2"></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="助记码">
                                                        <el-input v-model="formData.helpCode"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item
                                                            label="套餐价格"
                                                            prop="price">
                                                        <el-input v-model="formData.price"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="适用年龄">
                                                        <el-input v-model="formData.age"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="24">
                                                    <el-form-item label="说明">
                                                        <el-input v-model="formData.remark" type="textarea"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="24">
                                                    <el-form-item label="注意事项">
                                                        <el-input v-model="formData.attention" type="textarea"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>
                                    <el-tab-pane label="检查组信息" name="second">
										<div class="checkScrol">
											<table class="datatable">
												<thead>
												<tr>
													<th>选择</th>
													<th>项目编码</th>
													<th>项目名称</th>
													<th>项目说明</th>
												</tr>
												</thead>
												<tbody>
												<tr v-for="c in tableData">
													<td>
														<input :id="c.id" v-model="checkgroupIds" type="checkbox" :value="c.id">
													</td>
													<td><label :for="c.id">{{c.code}}</label></td>
													<td><label :for="c.id">{{c.name}}</label></td>
													<td><label :for="c.id">{{c.remark}}</label></td>
												</tr>
												</tbody>
											</table>
										</div>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="handleAdd()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>

                </div>
            </div>
        </div>
    </body>


    <script>
        var vue = new Vue({
            el: '#app',
            data:{
                dateRangeStr:null,
                activeName:'first',//添加/编辑窗口Tab标签名称
                pagination: {//分页相关属性
                    currentPage: 1,
                    pageSize:5,
                    total:100,
                    queryString:null,
                },
                dataList: null,//列表数据
                formData: {},//表单数据
                formData_isload: false,
                tableData:[],//添加表单窗口中检查组列表数据
                checkgroupIds:[],//添加表单窗口中检查组复选框对应id
                dialogFormVisible: false,//控制添加窗口显示/隐藏
                rules: {//校验规则
                    code: [{ required: true, message: '套餐编码为必填项', trigger:
                            'blur' }],
                    name: [{ required: true, message: '套餐名称为必填项', trigger:
                            'blur' }],
                    price: [{ required: true, message: "套餐价格为必填项", trigger:
                            'blur'}]
                },
                pickerOptions: {
                    shortcuts: [{
                        text: '最近一周',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近一个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近三个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
            },
            created() {
                this.findPage();
            },
            methods: {
                //添加
                handleAdd () {
                    this.$refs['dataAddForm'].validate((valid)=>{
                       if(valid){
                            axios.post("/setmeal/add.do?checkgroupIds="+this.checkgroupIds, this.formData)
                                .then((res)=>{
                            //         1） 提示成功或者失败
                            this.$message({
                                message:res.data.message,
                                type: res.data.flag ?"success":"error"
                            });

                            }).catch((err)=>{
                                this.$message.error(err);
                                console.log(err);
                            }).finally(()=>{
                                 //         2) 关闭弹出窗口
                                this.dialogFormVisible = false;
                                this.findPage();
                            });
                       }else{
                           return false;
                       }
                    });

                },
                //分页查询
                findPage() {
                    //1. 封装参数
                    this.dataList = null;
                    var param = {
                        currentPage: this.pagination.currentPage,
                        pageSize: this.pagination.pageSize,
                        queryString: this.pagination.queryString,
                        dateRangeList: this.dateRangeStr,
                    };
                    //2. 发送请求，查询数据
                    axios.post("/ordersettinglist/findByPage.do", param).then((res) => {
                        //数据显示
                        console.log(res);
                        this.dataList = res.data.rows;
                        this.pagination.total = res.data.total;
                        this.pagination.currentPage = res.data.currentPage;
                    }).catch((err) => {
                        this.$message.error(err);
                        console.log(err);
                    });
                },
                // 重置表单
                resetForm() {
                    //清空表单数据，切换第一个卡片，清空选中的检出组, 清空图片的路径
                    this.formData = {};
                    this.activeName = "first";
                    this.checkgroupIds = [];
                    this.imageUrl = null;
                },
                // 弹出添加窗口
                handleCreate() {
                    // 1. 弹出新建窗口
                    this.dialogFormVisible = true;
                    // 2. 重置表单数据
                    this.resetForm();
                    //3. 回显检查组信息
                    axios.get("/checkgroup/findAll.do").then((res)=>{
                        this.tableData = res.data.data;
                    }).catch((err)=>{
                        this.showMessage(err);
                        console.log(err);
                    });
                },
                //切换页码
                handleCurrentChange(currentPage) {
                    this.pagination.currentPage = currentPage;
                    this.findPage();
                },
                // 删除
                handleDelete(row) {
                    var id = row.id;
                    console.log(id);
                    // 1.弹出确认窗口
                    this.$confirm('此操作将永久删除与之相关的数据,是否继续?','提示',{
                        confirmButtonText: '确认删除',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(()=>{
                        axios.get("/ordersettinglist/delOrderSettingById.do?id="+id).then((res)=>{
                            this.$message({
                                type: res.data.flag ? 'success' : 'error',
                                message: res.data.message
                            });
                        }).catch((err)=>{
                            this.showMessage(err);
                            console.log(err);
                        }).finally(() => {
                            //4. 查询
                            this.findPage();
                        });
                    }).catch(() => {
                        // 取消删除操作
                        this.$message({
                            type: 'info',
                            message: '已取消删除'
                        });
                    });
                },
                showMessage(err){
                    if(err == 'Error: Request failed with status code 403'){
                        this.$message({
                            type: 'warning',
                            message: '权限不足'
                        });
                    }else{
                        this.$message({
                            type: 'warning',
                            message: "unkown error =>" + err
                        });
                    }
                }
            }
        })
    </script>
</html>
